import axios from 'axios';
import {API_NEW_VERSION} from '../api';

var qs = require('qs');

const FREIGHT_SHORTINGS = API_NEW_VERSION + 'freight/shortings';

const FREIGHT_SHORTINGS_STATUS = API_NEW_VERSION + 'freight/shortings/status';

const FREIGHT_SHORTING = API_NEW_VERSION + 'freight/shorting/';

const FREIGHT_SHORTINGS_BASES = API_NEW_VERSION + 'freight/shorting/bases';

const FREIGHT_SHORTINGS_DETAILS = API_NEW_VERSION + 'freight/shorting/details';

const FREIGHT_SHORTING_BASE = API_NEW_VERSION + 'freight/shorting/base/';

const FREIGHT_FILES_FIND_BY_FREIGHT_BASE_ID_AND_BILL_TYPE = API_NEW_VERSION + 'freight/files_find_by_freight_short_id_and_bill_type';

// 根据短途运价文件id,更改短途运价文件状态
export const findByShortBaseIdAndBillType = (id, billType) => {
  return axios.get(FREIGHT_FILES_FIND_BY_FREIGHT_BASE_ID_AND_BILL_TYPE, {params: {id: id, billType: billType}});
};

// 获取列表
export const searchFreightShort = params => {
  return axios.get(FREIGHT_SHORTINGS, {params: params});
};

// 保存基础运价文件
export const saveFreightShortBase = (params) => {
  return axios.post(FREIGHT_SHORTINGS_BASES, params);
};

// 保存运价文件
export const saveFreightShort = (params) => {
  return axios.post(FREIGHT_SHORTINGS, params);
};

// 保存基础运价文件详情
export const saveFreightShortBaseDetail = (params) => {
  return axios.post(FREIGHT_SHORTINGS_DETAILS, params);
};
// 根据短途运价文件id,更改短途运价文件状态
export const changeStatus = (id, status) => {
  return axios.post(FREIGHT_SHORTINGS_STATUS, qs.stringify({id: id, status: status}));
};

// 删除短途运价
export const deleteFreightShost = id => {
  return axios.delete(FREIGHT_SHORTING + id);
};

// 删除基础短途运价
export const deleteFreightShostBase = id => {
  return axios.delete(FREIGHT_SHORTING_BASE + id);
};
// 根据ID获取短途运价
export const getFreightShost = id => {
  return axios.get(FREIGHT_SHORTING + id);
};
// 根据ID获取基础短途运价
export const getFreightShostBase = id => {
  return axios.get(FREIGHT_SHORTING_BASE + id);
};

// 根据短途运价ID获取基础运价
export const searchFreightShortBase = params => {
  return axios.get(FREIGHT_SHORTINGS_BASES, {params: params});
};

export const saveFreightBaseDetail = (id, params) => {
  return axios.post(API_NEW_VERSION + 'freight/shorting/base/' + id + '/details', params);
};

export const clearFreightBase = (id) => {
  return axios.delete(API_NEW_VERSION + 'freight/shorting/' + id + '/clear');
};
